home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 19 / Amiga Plus Leser CD 19.iso / Tools / MorphOS / cvs-1.11.2 / source / amiga / netinclude / netinet / ip_fil.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-18  |  13.1 KB  |  419 lines

  1. /*
  2.  * Copyright (C) 1993-2001 by Darren Reed.
  3.  *
  4.  * The author accepts no responsibility for the use of this software and
  5.  * provides it on an ``as is'' basis without express or implied warranty.
  6.  *
  7.  * Redistribution and use, with or without modification, in source and binary
  8.  * forms, are permitted provided that this notice is preserved in its entirety
  9.  * and due credit is given to the original author and the contributors.
  10.  *
  11.  * The licence and distribution terms for any publically available version or
  12.  * derivative of this code cannot be changed. i.e. this code cannot simply be
  13.  * copied, in part or in whole, and put under another distribution licence
  14.  * [including the GNU Public Licence.]
  15.  *
  16.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  17.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  20.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26.  * SUCH DAMAGE.
  27.  */
  28.  
  29. #ifndef    _NETINET_IP_FIL_H
  30. #define    _NETINET_IP_FIL_H
  31.  
  32. #ifndef EXEC_TYPES_H
  33. #include <exec/types.h>
  34. #endif /* EXEC_TYPES_H */
  35.  
  36. #ifndef _SYS_IOCCOM_H
  37. #include <sys/ioccom.h>
  38. #endif /* _SYS_IOCCOM_H */
  39.  
  40. #ifndef _NET_IF_H
  41. #include <net/if.h>
  42. #endif /* _NET_IF_H */
  43.  
  44. #ifndef _NETINET_IN_H
  45. #include <netinet/in.h>
  46. #endif /* _NETINET_IN_H */
  47.  
  48. #include <stddef.h>
  49.  
  50. #define    SIOCADAFR    _IOW('r', 60, struct frentry *)
  51. #define    SIOCRMAFR    _IOW('r', 61, struct frentry *)
  52. #define    SIOCSETFF    _IOW('r', 62, ULONG)
  53. #define    SIOCGETFF    _IOR('r', 63, ULONG)
  54. #define    SIOCGETFS    _IOWR('r', 64, struct friostat *)
  55. #define    SIOCIPFFL    _IOWR('r', 65, LONG)
  56. #define    SIOCIPFFB    _IOR('r', 66, LONG)
  57. #define    SIOCADIFR    _IOW('r', 67, struct frentry *)
  58. #define    SIOCRMIFR    _IOW('r', 68, struct frentry *)
  59. #define    SIOCSWAPA    _IOR('r', 69, ULONG)
  60. #define    SIOCINAFR    _IOW('r', 70, struct frentry *)
  61. #define    SIOCINIFR    _IOW('r', 71, struct frentry *)
  62. #define    SIOCFRENB    _IOW('r', 72, ULONG)
  63. #define    SIOCFRSYN    _IOW('r', 73, ULONG)
  64. #define    SIOCFRZST    _IOWR('r', 74, struct friostat *)
  65. #define    SIOCZRLST    _IOWR('r', 75, struct frentry *)
  66. #define    SIOCAUTHW    _IOWR('r', 76, struct frauth_t *)
  67. #define    SIOCAUTHR    _IOWR('r', 77, struct frauth_t *)
  68. #define    SIOCATHST    _IOWR('r', 78, struct fr_authstat *)
  69. #define    SIOCSTLCK    _IOWR('r', 79, ULONG)
  70. #define    SIOCSTPUT    _IOWR('r', 80, struct ipstate_save *)
  71. #define    SIOCSTGET    _IOWR('r', 81, struct ipstate_save *)
  72. #define    SIOCSTGSZ    _IOWR('r', 82, struct natget)
  73. #define    SIOCGFRST    _IOWR('r', 83, struct ipfrstat *)
  74.  
  75. #define    SIOCADDFR    SIOCADAFR
  76. #define    SIOCDELFR    SIOCRMAFR
  77. #define    SIOCINSFR    SIOCINAFR
  78.  
  79. union i6addr {
  80.     ULONG    i6[4];
  81.     struct    in_addr    in4;
  82. };
  83.  
  84. typedef    struct    fr_ip    {
  85.     unsigned int
  86.         fi_v:4;        /* IP version */
  87.     unsigned int
  88.         fi_fl:4;    /* packet flags */
  89.     unsigned int
  90.         fi_tos:8;    /* IP packet TOS */
  91.     unsigned int
  92.         fi_ttl:8;    /* IP packet TTL */
  93.     unsigned int
  94.         fi_p:8;        /* IP packet protocol */
  95.     union    i6addr fi_src;    /* source address from packet */
  96.     union    i6addr fi_dst;    /* destination address from packet */
  97.     ULONG    fi_optmsk;    /* bitmask composed from IP options */
  98.     UWORD    fi_secmsk;    /* bitmask composed from IP security options */
  99.     UWORD    fi_auth;    /* authentication code from IP sec. options */
  100. } fr_ip_t;
  101.  
  102. #define    FI_OPTIONS    (FF_OPTIONS >> 24)
  103. #define    FI_TCPUDP    (FF_TCPUDP >> 24)    /* TCP/UCP implied comparison*/
  104. #define    FI_FRAG        (FF_FRAG >> 24)
  105. #define    FI_SHORT    (FF_SHORT >> 24)
  106. #define    FI_CMP        (FI_OPTIONS|FI_TCPUDP|FI_SHORT)
  107.  
  108. #define    fi_saddr    fi_src.in4.s_addr
  109. #define    fi_daddr    fi_dst.in4.s_addr
  110.  
  111. /*
  112.  * These are both used by the state and NAT code to indicate that one port or
  113.  * the other should be treated as a wildcard.
  114.  */
  115. #define    FI_W_SPORT    0x00000100
  116. #define    FI_W_DPORT    0x00000200
  117. #define    FI_WILDP    (FI_W_SPORT|FI_W_DPORT)
  118. #define    FI_W_SADDR    0x00000400
  119. #define    FI_W_DADDR    0x00000800
  120. #define    FI_WILDA    (FI_W_SADDR|FI_W_DADDR)
  121. #define    FI_NEWFR    0x00001000
  122.  
  123. typedef    struct    fr_info    {
  124.     APTR    fin_ifp;        /* interface packet is `on' */
  125.     struct    fr_ip    fin_fi;        /* IP Packet summary */
  126.     UWORD    fin_data[2];        /* TCP/UDP ports, ICMP code/type */
  127.     UBYTE    fin_out;        /* in or out ? 1 == out, 0 == in */
  128.     UBYTE    fin_rev;        /* state only: 1 = reverse */
  129.     UWORD    fin_hlen;        /* length of IP header in bytes */
  130.     UBYTE    fin_tcpf;        /* TCP header flags (SYN, ACK, etc) */
  131.     /* From here on is packet specific */
  132.     UBYTE    fin_icode;        /* ICMP error to return */
  133.     UWORD    fin_rule;        /* rule # last matched */
  134.     ULONG    fin_group;        /* group number, -1 for none */
  135.     struct    frentry *fin_fr;    /* last matching rule */
  136.     STRPTR    fin_dp;            /* start of data past IP header */
  137.     UWORD    fin_dlen;        /* length of data portion of packet */
  138.     UWORD    fin_id;            /* IP packet id field */
  139.     APTR    fin_mp;            /* pointer to pointer to mbuf */
  140.     UWORD    fin_plen;
  141.     UWORD    fin_off;
  142. } fr_info_t;
  143.  
  144. #define    fin_v        fin_fi.fi_v
  145. #define    fin_saddr    fin_fi.fi_saddr
  146. #define    fin_daddr    fin_fi.fi_daddr
  147. #define    fin_fl        fin_fi.fi_fl
  148.  
  149. /*
  150.  * Size for compares on fr_info structures
  151.  */
  152. #define    FI_CSIZE    offsetof(fr_info_t, fin_icode)
  153.  
  154. /*
  155.  * Size for copying cache fr_info structure
  156.  */
  157. #define    FI_COPYSIZE    offsetof(fr_info_t, fin_dp)
  158.  
  159. typedef    struct    frdest    {
  160.     APTR    fd_ifp;
  161.     struct    in_addr    fd_ip;
  162.     UBYTE    fd_ifname[IFNAMSIZ];
  163. } frdest_t;
  164.  
  165. typedef    struct    frpcmp    {
  166.     LONG    frp_cmp;    /* data for port comparisons */
  167.     UWORD    frp_port;    /* top port for <> and >< */
  168.     UWORD    frp_top;    /* top port for <> and >< */
  169. } frpcmp_t;
  170.  
  171. typedef    struct    frtuc    {
  172.     UBYTE    ftu_tcpfm;    /* tcp flags mask */
  173.     UBYTE    ftu_tcpf;    /* tcp flags */
  174.     frpcmp_t    ftu_src;
  175.     frpcmp_t    ftu_dst;
  176. } frtuc_t;
  177.  
  178. #define    ftu_scmp    ftu_src.frp_cmp
  179. #define    ftu_dcmp    ftu_dst.frp_cmp
  180. #define    ftu_sport    ftu_src.frp_port
  181. #define    ftu_dport    ftu_dst.frp_port
  182. #define    ftu_stop    ftu_src.frp_top
  183. #define    ftu_dtop    ftu_dst.frp_top
  184.  
  185. typedef    struct    frentry {
  186.     struct    frentry    *fr_next;
  187.     struct    frentry    *fr_grp;
  188.     LONG    fr_ref;        /* reference count - for grouping */
  189.     APTR    fr_ifa;
  190.     APTR    fr_oifa;
  191.     /*
  192.      * These are only incremented when a packet  matches this rule and
  193.      * it is the last match
  194.      */
  195.     ULONG    fr_hits;
  196.     ULONG    fr_bytes;
  197.     /*
  198.      * Fields after this may not change whilst in the kernel.
  199.      */
  200.     struct    fr_ip    fr_ip;
  201.     struct    fr_ip    fr_mip;    /* mask structure */
  202.  
  203.  
  204.     UWORD    fr_icmpm;    /* data for ICMP packets (mask) */
  205.     UWORD    fr_icmp;
  206.  
  207.     frtuc_t    fr_tuc;
  208.     ULONG    fr_group;    /* group to which this rule belongs */
  209.     ULONG    fr_grhead;    /* group # which this rule starts */
  210.     ULONG    fr_flags;    /* per-rule flags && options (see below) */
  211.     ULONG    fr_skip;    /* # of rules to skip */
  212.     ULONG    fr_loglevel;    /* syslog log facility + priority */
  213.     APTR    fr_func;    /* call this function */
  214.     LONG    fr_sap;
  215.     UBYTE    fr_icode;    /* return ICMP code */
  216.     UBYTE    fr_ifname[IFNAMSIZ];
  217.     UBYTE    fr_oifname[IFNAMSIZ];
  218.     struct    frdest    fr_tif;    /* "to" interface */
  219.     struct    frdest    fr_dif;    /* duplicate packet interfaces */
  220.     ULONG    fr_cksum;    /* checksum on filter rules for performance */
  221. } frentry_t;
  222.  
  223. #define    fr_v        fr_ip.fi_v
  224. #define    fr_proto    fr_ip.fi_p
  225. #define    fr_ttl        fr_ip.fi_ttl
  226. #define    fr_tos        fr_ip.fi_tos
  227. #define    fr_tcpfm    fr_tuc.ftu_tcpfm
  228. #define    fr_tcpf        fr_tuc.ftu_tcpf
  229. #define    fr_scmp        fr_tuc.ftu_scmp
  230. #define    fr_dcmp        fr_tuc.ftu_dcmp
  231. #define    fr_dport    fr_tuc.ftu_dport
  232. #define    fr_sport    fr_tuc.ftu_sport
  233. #define    fr_stop        fr_tuc.ftu_stop
  234. #define    fr_dtop        fr_tuc.ftu_dtop
  235. #define    fr_dst        fr_ip.fi_dst.in4
  236. #define    fr_src        fr_ip.fi_src.in4
  237. #define    fr_dmsk        fr_mip.fi_dst.in4
  238. #define    fr_smsk        fr_mip.fi_src.in4
  239.  
  240. #ifndef    offsetof
  241. #define    offsetof(t,m)    (LONG)((&((t *)0L)->m))
  242. #endif
  243.  
  244. #define    FR_CMPSIZ    (sizeof(struct frentry) - offsetof(frentry_t, fr_ip))
  245.  
  246. /*
  247.  * fr_flags
  248.  */
  249. #define    FR_BLOCK    0x00001    /* do not allow packet to pass */
  250. #define    FR_PASS        0x00002    /* allow packet to pass */
  251. #define    FR_OUTQUE    0x00004    /* outgoing packets */
  252. #define    FR_INQUE    0x00008    /* ingoing packets */
  253. #define    FR_LOG        0x00010    /* Log */
  254. #define    FR_LOGB        0x00011    /* Log-fail */
  255. #define    FR_LOGP        0x00012    /* Log-pass */
  256. #define    FR_LOGBODY    0x00020    /* Log the body */
  257. #define    FR_LOGFIRST    0x00040    /* Log the first byte if state held */
  258. #define    FR_RETRST    0x00080    /* Return TCP RST packet - reset connection */
  259. #define    FR_RETICMP    0x00100    /* Return ICMP unreachable packet */
  260. #define    FR_FAKEICMP    0x00180    /* Return ICMP unreachable with fake source */
  261. #define    FR_NOMATCH    0x00200    /* no match occured */
  262. #define    FR_ACCOUNT    0x00400    /* count packet bytes */
  263. #define    FR_KEEPFRAG    0x00800    /* keep fragment information */
  264. #define    FR_KEEPSTATE    0x01000    /* keep `connection' state information */
  265. #define    FR_INACTIVE    0x02000
  266. #define    FR_QUICK    0x04000    /* match & stop processing list */
  267. #define    FR_FASTROUTE    0x08000    /* bypass normal routing */
  268. #define    FR_CALLNOW    0x10000    /* call another function (fr_func) if matches */
  269. #define    FR_DUP        0x20000    /* duplicate packet */
  270. #define    FR_LOGORBLOCK    0x40000    /* block the packet if it can't be logged */
  271. #define    FR_NOTSRCIP    0x80000    /* not the src IP# */
  272. #define    FR_NOTDSTIP    0x100000    /* not the dst IP# */
  273. #define    FR_AUTH        0x200000    /* use authentication */
  274. #define    FR_PREAUTH    0x400000    /* require preauthentication */
  275. #define    FR_DONTCACHE    0x800000    /* don't cache the result */
  276.  
  277. #define    FR_LOGMASK    (FR_LOG|FR_LOGP|FR_LOGB)
  278. #define    FR_RETMASK    (FR_RETICMP|FR_RETRST|FR_FAKEICMP)
  279.  
  280. /*
  281.  * These correspond to #define's for FI_* and are stored in fr_flags
  282.  */
  283. #define    FF_OPTIONS    0x01000000
  284. #define    FF_TCPUDP    0x02000000
  285. #define    FF_FRAG        0x04000000
  286. #define    FF_SHORT    0x08000000
  287. /*
  288.  * recognized flags for SIOCGETFF and SIOCSETFF, and get put in fr_flags
  289.  */
  290. #define    FF_LOGPASS    0x10000000
  291. #define    FF_LOGBLOCK    0x20000000
  292. #define    FF_LOGNOMATCH    0x40000000
  293. #define    FF_LOGGING    (FF_LOGPASS|FF_LOGBLOCK|FF_LOGNOMATCH)
  294.  
  295. #define    FR_NONE 0
  296. #define    FR_EQUAL 1
  297. #define    FR_NEQUAL 2
  298. #define FR_LESST 3
  299. #define FR_GREATERT 4
  300. #define FR_LESSTE 5
  301. #define FR_GREATERTE 6
  302. #define    FR_OUTRANGE 7
  303. #define    FR_INRANGE 8
  304.  
  305. typedef    struct    filterstats {
  306.     ULONG    fr_pass;    /* packets allowed */
  307.     ULONG    fr_block;    /* packets denied */
  308.     ULONG    fr_nom;        /* packets which don't match any rule */
  309.     ULONG    fr_short;    /* packets which are short */
  310.     ULONG    fr_ppkl;    /* packets allowed and logged */
  311.     ULONG    fr_bpkl;    /* packets denied and logged */
  312.     ULONG    fr_npkl;    /* packets unmatched and logged */
  313.     ULONG    fr_pkl;        /* packets logged */
  314.     ULONG    fr_skip;    /* packets to be logged but buffer full */
  315.     ULONG    fr_ret;        /* packets for which a return is sent */
  316.     ULONG    fr_acct;    /* packets for which counting was performed */
  317.     ULONG    fr_bnfr;    /* bad attempts to allocate fragment state */
  318.     ULONG    fr_nfr;        /* new fragment state kept */
  319.     ULONG    fr_cfr;        /* add new fragment state but complete pkt */
  320.     ULONG    fr_bads;    /* bad attempts to allocate packet state */
  321.     ULONG    fr_ads;        /* new packet state kept */
  322.     ULONG    fr_chit;    /* cached hit */
  323.     ULONG    fr_tcpbad;    /* TCP checksum check failures */
  324.     ULONG    fr_pull[2];    /* good and bad pullup attempts */
  325.     ULONG    fr_badsrc;    /* source received doesn't match route */
  326.     ULONG    fr_badttl;    /* TTL in packet doesn't reach minimum */
  327.     ULONG    fr_ipv6[2];    /* IPv6 packets in/out */
  328. } filterstats_t;
  329.  
  330. /*
  331.  * For SIOCGETFS
  332.  */
  333. typedef    struct    friostat    {
  334.     struct    filterstats    f_st[2];
  335.     struct    frentry        *f_fin[2];
  336.     struct    frentry        *f_fout[2];
  337.     struct    frentry        *f_acctin[2];
  338.     struct    frentry        *f_acctout[2];
  339.     struct    frentry        *f_fin6[2];
  340.     struct    frentry        *f_fout6[2];
  341.     struct    frentry        *f_acctin6[2];
  342.     struct    frentry        *f_acctout6[2];
  343.     struct    frentry        *f_auth;
  344.     struct    frgroup        *f_groups[3][2];
  345.     ULONG    f_froute[2];
  346.     LONG    f_defpass;    /* default pass - from fr_pass */
  347.     BYTE    f_active;    /* 1 or 0 - active rule set */
  348.     BYTE    f_running;    /* 1 if running, else 0 */
  349.     BYTE    f_logging;    /* 1 if enabled, else 0 */
  350.     UBYTE    f_version[32];    /* version string */
  351.     LONG    f_locks[4];
  352. } friostat_t;
  353.  
  354. typedef struct    optlist {
  355.     UWORD ol_val;
  356.     LONG    ol_bit;
  357. } optlist_t;
  358.  
  359.  
  360. /*
  361.  * Group list structure.
  362.  */
  363. typedef    struct frgroup {
  364.     ULONG    fg_num;
  365.     struct    frgroup    *fg_next;
  366.     struct    frentry    *fg_head;
  367.     struct    frentry    **fg_start;
  368. } frgroup_t;
  369.  
  370.  
  371. /*
  372.  * Log structure.  Each packet header logged is prepended by one of these.
  373.  * Following this in the log records read from the device will be an ipflog
  374.  * structure which is then followed by any packet data.
  375.  */
  376. typedef    struct    iplog    {
  377.     ULONG    ipl_magic;
  378.     ULONG    ipl_count;
  379.     ULONG    ipl_sec;
  380.     ULONG    ipl_usec;
  381.     size_t    ipl_dsize;
  382.     struct    iplog    *ipl_next;
  383. } iplog_t;
  384.  
  385. #define IPL_MAGIC 0x49504c4d /* 'IPLM' */
  386.  
  387. typedef    struct    ipflog    {
  388.     UBYTE    fl_ifname[IFNAMSIZ];
  389.     UBYTE    fl_plen;    /* extra data after hlen */
  390.     UBYTE    fl_hlen;    /* length of IP headers saved */
  391.     UWORD    fl_loglevel;    /* syslog log level */
  392.     ULONG    fl_rule;
  393.     ULONG    fl_group;
  394.     ULONG    fl_flags;
  395.     ULONG    fl_lflags;
  396. } ipflog_t;
  397.  
  398.  
  399. #ifndef    ICMP_UNREACH_FILTER
  400. # define ICMP_UNREACH_FILTER 13
  401. #endif
  402.  
  403. #ifndef    IPF_DEFAULT_PASS
  404. # define IPF_DEFAULT_PASS FR_PASS
  405. #endif
  406.  
  407. #define    IPMINLEN(i, h)    ((i)->ip_len >= ((i)->ip_hl * 4 + sizeof(struct h)))
  408. #define    IPLLOGSIZE    8192
  409.  
  410. #define    IPF_OPTCOPY    0x07ff00    /* bit mask of copied options */
  411.  
  412. #define    IPL_LOGIPF    0    /* Minor device #'s for accessing logs */
  413. #define    IPL_LOGNAT    1
  414. #define    IPL_LOGSTATE    2
  415. #define    IPL_LOGAUTH    3
  416. #define    IPL_LOGMAX    3
  417.  
  418. #endif    /* _NETINET_IP_FIL_H */
  419.